草庐IT

C++ 空类或 typedef

全部标签

c++ - 在函数上使用 typedef

在下文中,我如何使用typedef语法定义我的函数?typedefvoidF();//declaremyfunctionFf;//errorFf{} 最佳答案 函数的定义将遵循通常的语法://declaremyfunctionFf;//itisexactlyequivalentto:voidf();//definitionvoidf(){cout要测试该定义确实是之前声明的函数的定义,只需调用函数f()>after声明和before定义(阅读main()中的注释)://declarationFf;intmain(){f();//at

模板化类中 typedef 的 C++ 错误

我正在尝试编写一个简单的模板化事件调度程序,但我遇到了我不理解的编译器错误,搜索它也没有任何帮助。我正在使用VisualStudio2013Express。这是我的代码:templateclassEventDispatcher{public:typedefvoid(EventHandler)(Tevent);EventDispatcher(){}~EventDispatcher(){}voidaddListener(conststd::stringeventName,EventHandlerhandler){}voidfireEvent(Tevent){}private:typedef

c++ - Typedef、模板和 const 关键字

我在使用带有const关键字(用于函数参数类型)的模板时遇到问题,为了说明这一点,我创建了一个小代码:templatestructMethodCallerFactory{typedefReturnType(*Type)(ClassType*,Args...);templatestructMethod{staticTypecreateMethodCaller(){ReturnType(*caller)(ClassType*,Args...)=[](ClassType*obj,Args...args)->ReturnType{ReturnType(ClassType::*ptr)(Args

c++ - 这个 typedef 是如何工作的?

我正在看这个cpp闪电谈话video它在0:37显示这段代码template>classQScopedPointer{typedefT*QScopedPointer::*RestrictedBool;//howdoesthiswork?//whynotQScopedPointersinceQScopedPointerisatemplate?public:inlineoperatorRestrictedBool()const{returnisNull()?Q_NULLPTR:&QScopedPointer::d;}inlineboolisNull()const{return!d;}pro

c++ - 如何使用函数签名的 typedef 作为 std::function 的类型参数?

当用作模板类型参数时,函数的typedef和使用裸函数类型之间肯定有区别。即,考虑#includetypedefstd::functionTF1;typedefvoid(*FooFn)(int);typedefstd::functionTF2;intmain(){TF1tf1;TF2tf2;return0;}我可以创建TF1但不能创建TF2(错误:aggregate'TF2tf2'的类型不完整,无法定义)。(参见ideoneexample。)有没有办法使用函数(签名)的typedef作为模板类型参数;具体来说,作为std::function?的类型参数(没有C++11标记,因为我对bo

c++ - 什么是最快的 C++ 类或 C 库将纬度和经度从十进制度数转换为字符串并返回

我正在寻找最好的C或C++代码来编码和解码来自/至double/char的十进制纬度和经度值。我更喜欢将代码从double转换为char[],反之亦然而不是C++字符串。如果您有代码片段,那也很棒。澄清一下:我需要将字符串Degrees/Minutes/Seconds转换为double然后再转换回字符串。我有3亿条记录,所以速度是一个大问题。参见:http://en.wikipedia.org/wiki/Geographic_coordinate_conversion 最佳答案 通过电子邮件与OP(amanda)合作,我们开发了一个

c++ - 模板化成员函数 typedef 无法编译

#include#includeusingnamespacestd;voidprintstr(conststring&s){coutclassTest{public:typedefvoid(*Func)(constA&);};typedefvoid(*Func)(conststring&);templatevoidbind(Test::Funcf,//在上面的代码中,我尝试使用另一个类中的函数指针typedef。如图所示,它没有编译,但是其他两行中的任何一行都没有注释,而不是Test::Funcf,。行,它编译得很好!这是我不能用C++做的事情吗?需要什么语法?使用g++4.4.3,我

c++ - std::vector 的 Typedef 和 ostream 运算符

我创建了一个Chromosome类,它最终只是一个带有ostream运算符的vector包装器,所以我决定改用typedefvector。但是,我在使用模板化的ostream运算符时遇到了问题……这是最好的方法吗?(我见过一些方法,但都没有奏效)templateclassChromosome{public:typedeftypenamestd::vectortype;typedeftypenamestd::pairptr_pair;};template//line19below:std::ostream&operator::type&chromosome){for(autoiter=c

c++ - 类中的typedef

有这样的代码:templateclassSomeClass{typedefboost::shared_ptrsPtr;typedefstd::vectorc;typedefc::iteratorcIt;//hereistheproblem};错误是:main.cpp:23:error:type‘std::vector,std::allocator>>’isnotderivedfromtype‘SomeClass’main.cpp:23:error:expected‘;’before‘cIt’如何在类中使用typedef来模板化参数?编辑:我想通了,对于g++,那一定是:typedeft

c++ - 在详细说明符中使用 typedef 名称

根据($3.4.4)后跟类键的typedef名称是无效的。但我不确定是哪个范围?例如:在下文中,如果在函数内部等block中使用了详细说明符,编译器不会报错。typedefclass{/*...*/}S;//invalidclassS;//okvoidfoo(){classS;}使用typedef-name在本地范围内声明类是否有效,为什么? 最佳答案 7.1.3第3段讲述:Inagivenscope,atypedefspecifiershallnotbeusedtoredefinethenameofanytypedeclaredi